<template>
  <div class="form">
    <el-dialog v-dialogDrag class="tiny-mce-dialog" :close-on-press-escape = "true" :show-close = 'false' center :modal="false" title="订单确认" width="500px" :visible.sync="isShow" @close="cancel('ruleForm')" :close-on-click-modal="false">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" size="mini" :label-width="formLabelWidth">
        <el-card class="box-card" >
          <div slot="header">
            <span>商品信息</span>
          </div>
          <el-row :gutter="24">
            <div >
            <my-img style="float: left;" :src="ruleForm.coalPic" />

            <div style="float: left;margin-left: 18px" >
              <div >
                <p>{{ruleForm.mineMouthName}} <span style="margin-left: 10px">{{ruleForm.coalName}}</span>  </p></div>

              <div><p>煤种：{{ruleForm.coalCategoryName}}</p></div>
              <div style="color: #FFBA00;size: 15px"><p>{{ruleForm.sellPrice}}元/吨（含税）</p></div>
            </div>
            </div>
          </el-row>
        </el-card>

        <el-card class="box-card" style="padding: 0">
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="运输方式:" :label-width="formLabelWidth" prop="transportWay">
                <div style="margin-left: 100px">{{ruleForm.transportWay | transportFilter}}</div>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="采购数量:" :label-width="formLabelWidth" prop="number">
                <div style="margin-left: 100px">{{ruleForm.number}}</div>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="运输费:" prop="freight" :label-width="formLabelWidth" >
                <el-input style="margin-left: 100px;width: 150px" v-model="ruleForm.freight" maxlength="5" clearable placeholder="请输入" >
                  <template slot="append">元/吨</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="7">
              <el-form-item label="煤款:" :label-width="formLabelWidth1" prop="totalPrice">
                <div style="color: #FFBA00;size: 15px">{{ruleForm.totalPrice}}</div>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="运费:" :label-width="formLabelWidth1" >
                <div style="color: #FFBA00;size: 15px">{{ruleForm.number * (ruleForm.freight == null ? 0 : ruleForm.freight)}}</div>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="合计:" :label-width="formLabelWidth1" >
                <div style="color: #FFBA00;size: 15px">{{ ruleForm.totalPrice + (ruleForm.number * (ruleForm.freight == null ? 0 : ruleForm.freight))}}</div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="box-card" style="float: left; width: 100%" >
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="收货人姓名" :label-width="formLabelWidth" prop="name">
                <div>{{ruleForm.name}}</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="收货人电话" :label-width="formLabelWidth" prop="phone">
                <div>{{ruleForm.phone}}</div>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="收货人地址" :label-width="formLabelWidth" prop="address">
                <div>{{ruleForm.address}}</div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" style="text-align:right" class="dialog-footer">
        <el-button type="info" size="mini" @click="cancel">取 消</el-button>
        <el-button type="primary" size="mini" v-loading.fullscreen.lock="fullscreenLoading" @click="update">确认订单</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import MyImg from '@/components/img/img'
export default {
  name: 'DriverStaff',
  props: ['showFormPanel', 'item'],
  data () {
    return {
      vehicleTypes: [],
      vehicleLengths: [],
      matchData:{},
      showOperation:false,
      fullscreenLoading: false,
      customVal: {imgName: ''},
      showTreeDialog: false,
      selectOrgExpandAll: false,
      ruleForm: this.item,
      roleOptions: [],
      formLabelWidth: '90px',
      formLabelWidth1: '55px',
      isShow: this.showFormPanel,
      rules: {
        carLoad: [
          { required: true, message: '请输入车辆载重', trigger: 'blur' }
        ]
      }
    }
  },
  filters: {
    formatStatus: function (val) {
      if (val === 'LOCK') {
        return false
      } else if (val === 'NORMAL') {
        return true
      }
      return '-'
    }
  },
  methods: {
    selectVehicleLengths (val) {
      if (!val){
        this.ruleForm.carLength = null
        return
      }
      let obj = {}
      obj = this.vehicleLengths.find((item) => {
        return item.id === val
      })
      this.ruleForm.carLength = obj.name
    },
    selectVehicleType (val) {
      if (!val){
        this.ruleForm.typeName = null
        return
      }
      let obj = {}
      obj = this.vehicleTypes.find((item) => {
        return item.id === val
      })
      this.ruleForm.typeName = obj.name
    },
    update() {
      let self = this
      self.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.fullscreenLoading = true
          self.ruleForm.payTotalFreight = self.ruleForm.number * (self.ruleForm.freight == null ? 0 : self.ruleForm.freight)
          self.$http.post('/api/orderMerchant/sure', self.ruleForm)
            .then(function (res) {
              self.fullscreenLoading = false
              self.cancel()
              self.$emit('refreshList')
            }).catch(function (error) {
              self.fullscreenLoading = false
              console.log(error)
            })
        }
      })
    },
    save () {
        let self = this
        let url = 'add'
        if (self.ruleForm.carOwnerId != null) {
          url = 'update'
        }
        if (objKey){
          objKey.forEach((value, index) => {
            if (index === 0){
              self.ruleForm.vehicleLicenseFirstPic = value.objKey  ?  imgValue + value.objKey : value.url
            }
          })
        }
        if (objKey1){
          objKey1.forEach((value, index) => {
            if (index === 0){
              self.ruleForm.vehicleLicenseSecondPic = value.objKey  ?  imgValue1 + value.objKey : value.url
            }
          })
        }
        if (objKey2) {
          objKey2.forEach((value, index) => {
            if (index === 0){
              self.ruleForm.carPhoto = value.objKey  ?  imgValue2 + value.objKey : value.url
            }
          })
        }

    },
    search(){
      let self = this
      self.$http.get("/api/systemController/getVehicleType").then(function(value) {
        if (value.ok){
          self.vehicleLengths = value.data.vehicleLengths
          self.vehicleTypes = value.data.vehicleTypes
        }
      })
    },
    cancel() {
      this.$refs['ruleForm'].resetFields()
      this.isShow = false
      this.$emit('update:showFormPanel', this.isShow)
    }
  },
  mounted: function() {
  },
  components: {
    MyImg
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.test {
  font-size: 13px;
  color: #606266;
  line-height: 15px;
  padding: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  font-weight: bold;
}
.el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
  margin-bottom: 15px;
}
.mark-body{
  position:fixed;
  left:0px;
  top:0px;
  background:rgba(0, 0, 0, 0.18);
  width:100%;  /*宽度设置为100%，这样才能使隐藏背景层覆盖原页面*/
  height:100%;
  filter:alpha(opacity=60);  /*设置透明度为60%*/
  opacity:0.6;  /*非IE浏览器下设置透明度为60%*/
  z-Index:999;
}
aside {
  /* background: #eef1f6; */
  /* padding: 6px 5px; */
  background: none;
  padding: 0px 24px;
  margin-bottom: 1px;
  border-radius: 2px;
  display: block;
  /* line-height: 50px; */
  /* font-size: 48px; */
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
  color: #2c3e50;
  /* -webkit-font-smoothing: antialiased; */
  -moz-osx-font-smoothing: grayscale;
}
</style>
